<template>
	<view>
		<view class="container">
			<view class="" style="width: 100%;padding: 10rpx;">
				{{articleData.title}}
			</view>
			<view class="row" style="margin-top: 30rpx; align-items: center;flex-wrap: wrap;">
				<text
					style="color: #818181;font-size: 26rpx;background-color: #F1F1F1;padding: 5rpx 5rpx;border-radius: 5rpx;">{{articleData.source}}</text>
				<text class="font-size-30" style="margin-left: 20rpx;">{{articleData.type}}</text>
				<text class="font-size-30" style="margin-left: 20rpx;">{{articleData.readingQuantity}}阅读</text>
				<text class="font-size-30" style="margin-left: 20rpx;">{{articleData.time}}</text>
			</view>
			<information-ad :adpid="adpid" v-if="iosStatus" />
			<rich-text :nodes="formatRichText(articleData.raw.content)"></rich-text>

			<information-ad :adpid="adpid" v-if="iosStatus"/>

			
		</view>
	</view>
</template>

<script>
	import informationAd from '@/components/ad/information-ad.vue'

	export default {
		components: {
			informationAd
		},
		data() {
			const articleData = this.$util.getDynamicConsultation()
			return {
				articleData,
				iosStatus:0 ,//ios审核时后台字典设置成0不显示
				adpid:"1947039492"
			};
		},
		onLoad() {
			// 添加Page viwe
			this.$util.addDynamicConsultationPv(this.articleData.raw.id)
		},
		onShow() {
			this.isAndroid = getApp().globalData.isAndroid;
			this.iosStatus = uni.getStorageSync("iosStatus")
			if(this.iosStatus&&!this.isAndroid){
				this.adpid = "1131480982"
			}
		},
		methods:{
			formatRichText(html){
			  let newContent= html.replace(/<img[^>]*>/gi,function(match,capture){
			    match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
			    match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
			    match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
			    return match;
			  });
			  newContent = newContent.replace(/style="[^"]+"/gi,function(match,capture){
			    match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
			    return match;
			  });
			  newContent = newContent.replace(/<br[^>]*\/>/gi, '');
			  newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"');
			  return newContent;
			}
		}
	}
</script>

<style lang="scss">
	.container {
		padding: 30rpx 35rpx;
	}

	.font-size-30 {
		font-size: 30rpx;
		color: #818181;
	}
</style>
